<?php
namespace app\www\controller;
class Article extends Base{

    //文章详情
    public function detail(){
        //文章
        $article_cat1 = $this->db->query('select * from article_cat where parent_id = ? order by sort asc',[1]);
        foreach ($article_cat1 as $key => $value) {
            //分类下文章
            $article_cat1[$key]['article_list'] = $this->db->query('select * from article where cat_id = ? and status = 0 order by sort asc',[$value['id']]);
        }
        $id = intval($this->get['id']);
        //查询文章
        $article_detail = $this->db->find('article',$id);
        $this->fetch(['article_detail'=>$article_detail,'article_cat1'=>$article_cat1]);
    }

    //文章列表
    public function lists(){
        $d = $this->get();
        $order = 0;
        $map = [];
        $map[] = ["and","cat_id","=",8];
        $map[] = ["and","status","=",0];
        $page = isset($d['page']) ? (int)$d['page'] : 1;
        if(isset($d["order"]))$order=$d["order"];
        $article_list = m("article","c")->lists($map,$order, $page);
        //商品列表推荐位5条数据
        $list = [
            "article_list"=>$article_list[0],
            "page_count"=>$article_list[1],
            "page" => $page
        ];
        $this->fetch($list);
    }

    //公告详情
    public function detail1(){
        $id = intval($this->get['id']);
        //查询文章
        $article_detail = $this->db->find('article',$id);
        //查询公告分类
        $article_cat = $this->db->find('article_cat',$article_detail['cat_id']);
        $this->fetch(['article_detail'=>$article_detail,'article_cat'=>$article_cat]);
    }
}
?>
